package com.lsq.springboot;

import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;

import java.util.Map;

/**
 * @author lsq
 * @description TODO
 * @date 2023/9/8
 */
public class LsqOnClassCondition implements Condition {
    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
        //判断是否有tomcat依赖
        Map<String, Object> annotationAttributes = metadata.getAnnotationAttributes(LsqConditionOnClass.class.getName());
        String value = (String)annotationAttributes.get("value");
        try {
            context.getClassLoader().loadClass(value);
        } catch (ClassNotFoundException e) {
            return false;
        }
        return true;
    }
}
